#!/bin/sh
#
# Run a simple backup  using the compressed option
#   then backup a second time and finally restore it
#
TestName="two-jobs-test"
JobName=Two-Jobs
. scripts/functions

cwd=`pwd`
scripts/cleanup
scripts/copy-test-confs
change_jobname CompressedTest $JobName

# Directory to backup.
# This directory will be created by setup_data().
BackupDirectory="${tmp}/data"

# Use a tgz to setup data to be backed up.
# Data will be placed at "${tmp}/data/".
setup_data data/small.tgz

# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list".
echo "${BackupDirectory}" >${tmp}/file-list


start_test

cat >tmp/bconcmds <<END_OF_DATA
setdebug level=150  storage=File
@$out /dev/null
messages
@$out tmp/log1.out
label storage=File volume=TestVolume001
run job=$JobName yes
wait
messages
quit
END_OF_DATA

run_susan
check_for_zombie_jobs storage=File

echo "Backup 1 done"
change_files
#
# run a second job
#
cat >tmp/bconcmds <<END_OF_DATA
@$out /dev/null
messages
@$out tmp/log1.out
run job=$JobName
yes
wait
messages
@#
@# now do several restores to ensure we cleanup between jobs
@#
@$out /dev/null
restore where=${cwd}/tmp/susan-restores select all storage=File done
yes
wait
restore where=${cwd}/tmp/susan-restores select all storage=File done
yes
wait
@$out tmp/log2.out
restore where=${cwd}/tmp/susan-restores select storage=File
unmark *
mark *
done
yes
wait
messages
quit
END_OF_DATA

run_bconsole
check_for_zombie_jobs storage=File
stop_susan

check_two_logs
check_restore_diff
end_test
